package middleware

import (
	"github.com/gin-gonic/gin"
	"log"
	"time"
)

func Cors() gin.HandlerFunc  {
	return func(c *gin.Context) {
		t := time.Now()
		c.Writer.Header().Set("Access-Control-Allow-Origin", "*")
		c.Writer.Header().Set("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE")
		c.Writer.Header().Set("Access-Control-Allow-Headers", "Action, Module, X-PINGOTHER, Content-Type, Content-Disposition")
		c.Next()
		latency := time.Since(t)
		log.Print("--", latency)
		status := c.Writer.Status()
		log.Println("==", status)
	}
}